package com.rpframework.website.friendly.act.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.rpframework.core.BaseAct;
import com.rpframework.module.common.domain.Slideshow;
import com.rpframework.module.common.service.SlideshowService;
import com.rpframework.website.friendly.domain.Aboutus;
import com.rpframework.website.friendly.domain.Linkus;
import com.rpframework.website.friendly.domain.News;
import com.rpframework.website.friendly.domain.Progress;
import com.rpframework.website.friendly.service.AboutusService;
import com.rpframework.website.friendly.service.LinkusService;
import com.rpframework.website.friendly.service.NewsService;
import com.rpframework.website.friendly.service.ProgressService;


/**
 * 导航连接
 * @author Andy_hqr
 * @date 2015年8月13日 下午5:34:27
 */
@Controller
@RequestMapping("/")
public class IndexAct extends BaseAct{
	public @Resource LinkusService linkService;
	public @Resource NewsService newsService;
	public @Resource AboutusService aboutusService;
	public @Resource SlideshowService slideService;
	public @Resource ProgressService progressService;
	

	@RequestMapping
	public String execute(Map<Object, Object> model){
		
		return index(model);
	}
	// 首页
	@RequestMapping("/index")
	public String index(Map<Object, Object> model){
		/*联系我们*/
		Linkus linkus = linkService.select(1);
		model.put("linkus", linkus);
		return "/web/index";
	}
	// 新闻资讯
	@RequestMapping("/news")
	public String news(Map<Object, Object> model){
		/*三张轮播图是推荐的 最多取15张，取最新的15张*/
		List<News> rec = newsService.getRecommenderByNum(15);
		/*新闻取最新的6张，最低6张*/
		List<News> news = newsService.getNewByNum(6); 
		model.put("recommenderList", rec);
		model.put("newsList", news);
		Linkus linkus = linkService.select(1);
		model.put("linkus", linkus);
		return "/web/news";
	}
	// 新闻资讯
		@RequestMapping("/news/detail")
		public String news(Map<Object, Object> model,
				@RequestParam(value="id") Integer id
				){
			News news = newsService.select(id);
			model.put("news", news);
			Linkus linkus = linkService.select(1);
			model.put("linkus", linkus);
			
			return "/web/detail";
		}
		// 下一篇
		@RequestMapping("/news/detailpage")
		public String detailpage(Map<Object, Object> model,
				@RequestParam(value="id") Integer id,
				@RequestParam(value="type") Integer type//1上一篇  2下一篇
				){
			if(type == 1){
				id = newsService.getUpId(id);
				if(id==null) id=newsService.getMaxId();
			}else{
				id = newsService.getNextId(id);
				if(id==null) id= newsService.getMinId();
			}
			News news = newsService.select(id);
			model.put("news", news);
			Linkus linkus = linkService.select(1);
			model.put("linkus", linkus);
			return "/web/detail";
		}
	// 关于我们
	@RequestMapping("/aboutus")
	public String aboutus(
			@RequestParam(value="type") Integer type,
			Map<Object, Object> model){
		Linkus linkus = linkService.select(1);
		model.put("linkus", linkus);
		/*简介1  大家庭2   招聘3*/
		Aboutus aboutus = aboutusService.selectByType(type);
		model.put("aboutus", aboutus);
		if(type == 1){
			return "/web/aboutus";
		}
		if(type == 2){
			return "/web/aboutus-home";
		}
		if(type == 3){
			return "/web/joinus";
		}
		return "web/aboutus";
	}
	// 关于我们-办公环境
	@RequestMapping("/aboutus-envir")
	public String aboutusEnvir(
			Map<Object, Object> model){
		Linkus linkus = linkService.select(1);
		model.put("linkus", linkus);
		List<Slideshow> slideList =slideService.queryAll(); 
		model.put("slideList", slideList);
		return "web/aboutus-envir";
	}
	// 关于我们-项目进程
	@RequestMapping("/aboutus-progress")
	public String aboutusProgress(
			Map<Object, Object> model){
		Linkus linkus = linkService.select(1);
		model.put("linkus", linkus);
		List<Progress> progressList = progressService.getByNum(7);
		model.put("progressList", progressList);
		return "web/aboutus-progress";
	}
	// 联系我们
	@RequestMapping("/linkus")
	public String linkus(Map<Object, Object> model){
		Linkus linkus = linkService.select(1);
		model.put("linkus", linkus);
		return "/web/linkus";
	}
	// 加入我们
	@RequestMapping("/joinus")
	public String joinus(Map<Object, Object> model){
		/*联系我们*/
		Linkus linkus = linkService.select(1);
		model.put("linkus", linkus);
		return "/web/joinus";
	}
//	@SuppressWarnings({ "unchecked", "rawtypes" })
//	@RequestMapping("/map")
//	public String map(@RequestParam(value="pager", required=false) Pager pager,
//			@RequestParam(value="searchMap",required=false) String searchMap,
//			Map<Object, Object> model){
//		if(pager == null) {
//			pager = new Pager();
//		}
//		if(StringUtils.isNotBlank(searchMap)){
//			pager.getSearchMap().put("title", searchMap);
//			model.put("searchMap", searchMap);
//		}
//		pager.getSearchMap().put("state", String.valueOf(DMQHConstant.GlobalVariable.GLOBAL_STATE_SHOW)); // 搜索状态正常的商品
//		pager = maplineService.getMaplinePager(pager);
//		model.put("mapPager", pager);
//		// 热门导游
//		List<Guide> guideList = guideService.querCommendGuide(4);
//		model.put("guideList", guideList);
//		
//		// 热门租车
//		List<Rcar> rcarList = rcarService.querCommendRcar(4);
//		model.put("rcarList", rcarList);
//		
//		Mapline mapline = maplineService.querrTitleMapline();
//		if(mapline != null){
//			Spots spots = spotsService.select(mapline.getSpotsId());
//			mapline.setSpots(spots);
//		}
//		model.put("mapline", mapline);
//		String NOWTIME = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
//		List<Alimama> iconList = alimamaService.getSearchIcon(2,NOWTIME);
//		model.put("iconList", iconList);
//		return "/web/map";
//	}
//	
	
}
